﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lanscape.DMS.Business
{
    public class Folder
    {
        bool isDataLoaded = false;
        bool isNew = false;
        bool isDirty = false;

        Guid id = Guid.Empty;
        string name = string.Empty;
        List<Folder> folders = new List<Folder>();
        List<Document> documents = new List<Document>();
        string createdBy = string.Empty;
        DateTime createdDate = DateTime.MinValue;
        string updatedBy = string.Empty;
        DateTime updatedDate = DateTime.MinValue;

        public Folder()
        {
            this.isNew = true;
            this.isDirty = true;
            this.id = Guid.NewGuid();
        }

        public Folder(Guid pFolderID)
        {
            this.id = pFolderID;
        }

        public Guid ID
        { get { return this.id; } }
                
        public string Name
        {
            get
            {
                if (this.isDataLoaded) { return this.name; }
                else
                {
                    loadRest();
                    return name;
                }
            }

            set
            {
                this.name = value;
                this.isDirty = true;
            }
        }        

        public List<Folder> Folders
        {
            get
            {
                if (this.isDataLoaded) { return this.folders; }
                else
                {
                    loadRest();
                    return folders;
                }
            }

            set
            {
                this.folders = value;
                this.isDirty = true;
            }
        }

        public List<Document> Documents
        {
            get
            {
                if (this.isDataLoaded) { return this.documents; }
                else
                {
                    loadRest();
                    return documents;
                }
            }

            set
            {
                this.documents = value;
                this.isDirty = true;
            }
        }

        public string CreatedBy
        {
            get
            {
                if (this.isDataLoaded) { return this.createdBy; }
                else
                {
                    loadRest();
                    return createdBy;
                }
            }

            set
            {
                this.createdBy = value;
                this.isDirty = true;
            }
        }

        public DateTime CreatedDate
        {
            get
            {
                if (this.isDataLoaded) { return this.createdDate; }
                else
                {
                    loadRest();
                    return createdDate;
                }
            }

            set
            {
                this.createdDate = value;
                this.isDirty = true;
            }
        }

        public string UpdatedBy
        {
            get
            {
                if (this.isDataLoaded) { return this.updatedBy; }
                else
                {
                    loadRest();
                    return updatedBy;
                }
            }

            set
            {
                this.updatedBy = value;
                this.isDirty = true;
            }
        }

        public DateTime UpdatedDate
        {
            get
            {
                if (this.isDataLoaded) { return this.updatedDate; }
                else
                {
                    loadRest();
                    return updatedDate;
                }
            }

            set
            {
                this.updatedDate = value;
                this.isDirty = true;
            }
        }

        private void loadRest()
        {
            throw new NotImplementedException();
        }

        public void Save()
        {
            string script = "";

            if (isDirty)
            {

            }
        }
    }
}
